package hbt;

import hbt.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import modelo.Rodamiento;

public class HibernateRodamientoDAO {
	private static HibernateRodamientoDAO instancia = null;
	private static SessionFactory sf = null;

	public static HibernateRodamientoDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibernateRodamientoDAO();
		} 
		return instancia;
	}
	
	public void grabarRodamiento(Rodamiento rod){
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(rod);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void eliminarRodamiento(Rodamiento rod) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.delete(rod);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void modificarRodamiento(Rodamiento rod) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.merge(rod);
		session.flush();
		session.getTransaction().commit();
		session.close();
		
	}
	
	public Rodamiento consultarRodamiento(String codigoFabricante) {
		Session session = sf.openSession();
		session.beginTransaction();
		Rodamiento rod = (Rodamiento) session.get(Rodamiento.class, codigoFabricante);
		return rod;
		
	}
	
	
}
